package com.eastfair.config.controller.entitycontroller;

import com.eastfair.config.entity.InterfaceAccount;
import com.eastfair.config.service.entityservice.InterfaceAccountService;
import com.eastfair.core.base.R;
import com.eastfair.projectcore.vo.ConfigAttributeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 第三方账号控制类
 * <p>
 * Date:2021/8/7
 * Time:15:37
 *
 * @author zjn
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/interfaceAccount")
@Api(value = "第三方账号控制类", tags = "第三方账号控制类")
public class InterfaceAccountController {

    @Autowired
    private InterfaceAccountService interfaceAccountService;

    /**
     * 获取第三方账号属性信息
     *
     * @return
     */
    @GetMapping("/getAttributes")
    @ApiOperation(value = "获取第三方账号属性信息", notes = "获取第三方账号属性信息")
    public R<List<ConfigAttributeVO>> getInterfaceAccountAttributes() {
        return R.success(interfaceAccountService.getAttributes());
    }

    /**
     * 获取第三方账号列表
     *
     * @param interfaceAccount 第三方账号列表过滤条件
     * @return
     */
    @PostMapping("/getList")
    @ApiOperation(value = "获取第三方账号列表", notes = "获取第三方账号列表")
    public R<List<InterfaceAccount>> getList(@RequestBody(required = false) InterfaceAccount interfaceAccount) {
        return R.success(interfaceAccountService.getList(interfaceAccount));
    }

    /**
     * 获取第三方账号
     *
     * @param flagId 标识id
     * @return
     */
    @GetMapping("/get/{flagId}")
    @ApiOperation(value = "获取第三方账号", notes = "获取第三方账号")
    public R<InterfaceAccount> getInterfaceAccount(@PathVariable("flagId") Long flagId) {
        return interfaceAccountService.get(flagId);
    }

    /**
     * 根据条件获取单个第三方账号
     * 必填参数：
     * platformType 平台类型
     *
     * @param interfaceAccount 第三方账号过滤条件
     * @return 第三方账号实体
     */
    @PostMapping("/getByEntity")
    @ApiOperation(value = "根据条件获取单个第三方账号", notes = "根据条件获取单个第三方账号")
    public R<InterfaceAccount> getByEntity(@RequestBody @Validated({InterfaceAccount.VerifyGetByEntity.class}) InterfaceAccount interfaceAccount) {
        return interfaceAccountService.getByEntity(interfaceAccount);
    }

    /**
     * 新增第三方账号
     *
     * @param interfaceAccount 第三方账号实体
     * @return 是否成功
     */
    @PostMapping("/saveEntity")
    @ApiOperation(value = "新增第三方账号", notes = "新增第三方账号")
    public R<Boolean> saveEntity(@RequestBody InterfaceAccount interfaceAccount) {
        return interfaceAccountService.saveEntity(interfaceAccount);
    }

    /**
     * 删除第三方账号
     *
     * @param flagId 第三方账号标识id
     * @return 是否成功
     */
    @DeleteMapping("/{flagId}")
    @ApiOperation(value = "删除第三方账号", notes = "删除第三方账号")
    public R<Boolean> deleteEntity(@PathVariable("flagId") Long flagId) {
        return interfaceAccountService.deleteEntity(flagId);
    }

    /**
     * 修改第三方账号信息
     *
     * @param interfaceAccount 第三方账号信息
     * @return 是否成功
     */
    @PutMapping("/updateEntity")
    @ApiOperation(value = "修改第三方账号信息", notes = "修改第三方账号信息")
    public R<Boolean> updateEntity(@RequestBody InterfaceAccount interfaceAccount) {
        return interfaceAccountService.updateEntity(interfaceAccount);
    }

}
